package zozopo.warehouse;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import zozopo.background.operator.operations.OperatorTB;
import zozopo.background.operator.operations.OperatorlimitedTB;
import zozopo.user.operations.UserTB;
import zozopo.warehouse.operations.GoodsOS;
import zozopo.warehouse.operations.GoodsTB;
import zozopo.warehouse.operations.GoodsclassOS;
import zozopo.warehouse.operations.GoodsclassTB;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class AddGoodsclassAction 
	extends ActionSupport implements Action,SessionAware{
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		private static final String limitedCode ="WAREHOUSE.GOODS.CLASS.ADD";
		
		//传入参数
		private int parentid_goodsclass;
		private String name_goodsclass= "";
		
		private String remark_goodsclass = "";
		
		
		//传出参数
		private GoodsclassTB goodsclass;
		
		private Map<Object, Object> session;
		public void setSession(Map arg0) {
			// TODO Auto-generated method stub
			session = arg0;
		}
		public String execute(){
			GoodsclassOS goodsclassOS = new GoodsclassOS();
			
			goodsclass = new GoodsclassTB();
			goodsclass.setName_goodsclass(name_goodsclass);
			goodsclass.setParentid_goodsclass(parentid_goodsclass);
			goodsclass.setRemark_goodsclass(remark_goodsclass);
			
			goodsclassOS.insert(goodsclass); 
			goodsclass = goodsclassOS.getGoodsclassById(goodsclassOS.getMaxId());
			goodsclassOS.releaseConnection();
			
			return SUCCESS; 
			
		}
		
		public void validate() {
			//权限处理
			OperatorTB operator = (OperatorTB)session.get("operatorInfo"); 
		
			if(operator == null){
				addFieldError("errormessage",getText("operator.timeoutornotlogin"));
				return ; 
			} 
			
			//用户权限
			Map<String,OperatorlimitedTB> operatorlimitedMap = (Map<String,OperatorlimitedTB>)session.get("operatorlimitedMap");
			
			if(operatorlimitedMap.get(limitedCode) == null){
				addFieldError("errormessage","用户未有添加产品类别权限.");
				return;
			}
		}
		
		
		public static String getLimitedcode() {
			return limitedCode;
		}
		public int getParentid_goodsclass() {
			return parentid_goodsclass;
		}
		public void setParentid_goodsclass(int parentid_goodsclass) {
			this.parentid_goodsclass = parentid_goodsclass;
		}
		public String getName_goodsclass() {
			return name_goodsclass;
		}
		public void setName_goodsclass(String name_goodsclass) {
			this.name_goodsclass = name_goodsclass;
		}
		
		public GoodsclassTB getGoodsclass() {
			return goodsclass;
		}
		public void setGoodsclass(GoodsclassTB goodsclass) {
			this.goodsclass = goodsclass;
		}
		public String getRemark_goodsclass() {
			return remark_goodsclass;
		}
		public void setRemark_goodsclass(String remark_goodsclass) {
			this.remark_goodsclass = remark_goodsclass;
		}
		
}
